from rest_framework.generics import (CreateAPIView, ListAPIView)
from . import models
from .serializers import (OrderModelSerializer, UserOrderModelSerializer)
from rest_framework.permissions import IsAuthenticated


class OrderAPIView(CreateAPIView):
    """
    订单结算视图
    """
    queryset = models.Order.objects.filter(is_show=True, is_deleted=False)
    serializer_class = OrderModelSerializer
    permission_classes = [IsAuthenticated, ]


class UserOrderAPIView(ListAPIView):
    """
    用户订单展示视图
    """
    permission_classes = [IsAuthenticated, ]
    serializer_class = UserOrderModelSerializer

    def get_queryset(self):
        return models.Order.objects.filter(user_id=self.request.user.id)
